#!/usr/bin/env python
# encoding: utf-8
"""
for_flash.py

Created by Manabu Terada on 2009-09-26.
Copyright (c) 2009 CMScom. All rights reserved.
"""

from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner
from zope.component import getMultiAdapter
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

class ForFlashView(BrowserView):
    
    template = ViewPageTemplateFile('for_flash.pt')

    def __call__(self):
        response = self.request.response
        response.setHeader('Content-Type','application/x-xml')
        return self.template()

    def get_items(self):
        context = aq_inner(self.context)
        catalog = getToolByName(context, 'portal_catalog')
        portal_state = getMultiAdapter((self.context, self.request), 
                                        name=u'plone_portal_state')
        portal = portal_state.portal()
        flash_img_path = '/flash_img'
        if not flash_img_path.startswith('/'):
            flash_img_path = '/' + flash_img_path
        path = '/'.join(portal.getPhysicalPath()) + flash_img_path
        limit = 5
        # state = 'published'
        return catalog(portal_type='Image',
                       # review_state=state,
                       path=path,
                       sort_on='getObjPositionInParent',
                       sort_order='ascending',
                       sort_limit=limit)[:limit]
